<?php
$model = new Model();
$ans = $model->getdoc();
	$aUsers = array(
		"Category1, Subcategory1",
		"Category2, Subcategory2",
		"Category3, Subcategory3",
		"Category4, Subcategory4",
		"Category5, Subcategory5",
		"Category6, Subcategory6",
		"Category7, Subcategory7",
		"Category8, Subcategory8",
		"Category9, Subcategory9",
		"Category10, Subcategory10"
	);
	
	
	$aInfo = array(
		"heading1",
		"heading2",
		"heading3",
		"heading4",
		"heading5",
		"heading6",
		"heading7",
		"heading8",
		"heading9",
		"heading10"
	);
	
	$input = strtolower( $_GET['input'] );
	$len = strlen($input);
	$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 0;
	
	$aResults = array();
	$count = 0;
	
	if ($len)
	{
		for ($i=0;$i<count($aUsers);$i++)
		{
			// had to use utf_decode, here
			// not necessary if the results are coming from mysql
			//
			//if (strtolower(substr(utf8_decode($aUsers[$i]),0,$len)) == $input)
			if(strpos(strtolower($aUsers[$i]),$input) !== false)
			{
				$count++;
				$aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aInfo[$i]) );
			}
			
			if ($limit && $count==$limit)
				break;
		}
	}
	
	
	header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
	header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
	header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
	header ("Pragma: no-cache"); // HTTP/1.0
		header("Content-Type: application/json");
	
		echo "{\"results\": [";
		$arr = array();
		for ($i=0;$i<count($aResults);$i++)
		{
			$arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"".$aResults[$i]['value']."\", \"info\": \"".$aInfo[$i]."\"}";
		}
		echo implode(", ", $arr);
		echo "]}";
	
?>